/*
    Copyright (C) 2011 Rodrigo Castaño - Hugo Arregui, FuDePAN

    This file is part of the Prot-Filer Library

    Prot-Filer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Prot-Filer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Prot-Filer.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef BACKBONES_UTILS_H
#define BACKBONES_UTILS_H
#include "prot-filer/base.h"

namespace backbones_utils
{

using namespace prot_filer;
class DummyFilter
{
public:
    bool operator()(unsigned int /*index*/, const BasicProtein& /*patm*/, int /*at*/) const
    {
        return true;
    }
};

//This function copy de rotation matrix
inline void copymat(float* A, const float* B)
{
    memcpy(A, B, 16 * sizeof(float));
}

void semilla(BasicProtein& atm, float* R);

void angles2coord(BasicProtein& protein, const AnglesMapping& angles_mapping, const AnglesData& angles_data);

void int2car(float* pT, float bon, float cosang, float sinang, float costor, float sintor, BasicProtein& patm, int at, AtomType tipo);

template<class F>
bool poneres(float* pR, float cossi, float sinsi, float cosfi, float sinfi, BasicProtein& patm, int resN, const F& filter)
{
    float T[16];

    /*Guardo la anterior*/
    copymat(T, pR);

    int at = 3 * (resN - 1) - 1;

    at++;
    int2car(T, b_C_N, cos_a_CA_C_N, sin_a_CA_C_N, cossi, sinsi, patm, at, N);
    if (!filter(1, patm, at))
    {
        return false;
    }

    at++;
    int2car(T, b_N_CA, cos_a_C_N_CA, sin_a_C_N_CA, cos_OMEGA , sin_OMEGA, patm, at, CA);
    if (!filter(2, patm, at))
    {
        return false;
    }

    at++;
    int2car(T, b_CA_C, cos_a_N_CA_C, sin_a_N_CA_C, cosfi, sinfi, patm, at, C);
    if (!filter(3, patm, at))
    {
        return false;
    }

    copymat(pR, T);
    return true;
}
}
#endif
